package com.second.teacher.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.second.common.pojo.Teacher;
import com.second.common.vo.Result;
import com.second.teacher.service.TeacherService;
import com.second.teacher.vo.TeacherVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @program: second-education-parent
 * @description:
 * @author: 王子朋
 * @create: 2023-05-26 19:06
 **/
@RestController
@RequestMapping("/core/teacher")
@Api(tags = "查询讲师表的类")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @ApiOperation(value ="分页条件查询老师")
    @PostMapping("/findTeacher/{current}/{pageSize}")
    public Result findAll(@PathVariable Integer current, @PathVariable Integer pageSize, @RequestBody TeacherVo teacherVo){
        Page<Teacher> teacherPage = teacherService.findByConditionPage(current, pageSize, teacherVo);
        return Result.success(teacherPage);
    }
    @ApiOperation(value ="修改教师状态")
    @PostMapping("/changeStatus")
    public Result status(@RequestParam String id, @RequestParam String status){
        int row = teacherService.updateStatus(id, status);
        return Result.success();

    }

    @ApiOperation(value ="修改教师状态")
    @PostMapping("/status")
    public Result status(@RequestBody Teacher eduTeacher){
        Teacher teacher = teacherService.findOneById(eduTeacher.getId());
        teacher.setStatus(eduTeacher.getStatus());
        teacher.setGmtModified(LocalDateTime.now());
        teacherService.update(teacher);
        return Result.success();
    }
    @ApiOperation(value ="修改表单内容")
    @PostMapping("/updateTeacher")
    public Result updataTeacher(@RequestBody Teacher eduTeacher){
        Teacher teacher = new Teacher();
        teacher.setName(eduTeacher.getName());
        teacher.setMobile(eduTeacher.getMobile());
        teacher.setIntro(eduTeacher.getIntro());
        teacher.setEmail(eduTeacher.getEmail());
        teacher.setId(eduTeacher.getId());
        teacher.setGmtModified(eduTeacher.getGmtModified());
        teacherService.updateById(teacher);
        return Result.success();
    }
    @ApiOperation(value ="查询讲师审核表")
    @PostMapping("/findTeacherCheck/{current}/{pageSize}")
    public Result findCheckTeacher(@PathVariable Integer current,@PathVariable Integer pageSize,@RequestBody TeacherVo teacherVo){
        Page<Teacher> checkTeacher = teacherService.findCheckTeacher(current, pageSize, teacherVo);
        return Result.success(checkTeacher);

    }
    @ApiOperation(value ="修改审核列表审核状态")
    @PostMapping("update")
    public Result updateshenhe(@RequestBody Teacher teacher){
        int i = teacherService.updateshenhe(teacher);
        return Result.success(i);
    }

}
